class Solution {
public:
    int compareVersion(string version1, string version2) {
        
        vector<int> vecArr1,vecArr2;
        int cur=0;
        for(int i=0;i<version1.size();++i){
            if(version1[i]=='.'){
                vecArr1.push_back(cur);
                cur=0;
            }
            else{
                int t=version1[i]-'0';
                cur=cur*10+t;
            }
        }
        if(cur!=0){
            vecArr1.push_back(cur);
        }
        cur=0;
        for(int i=0;i<version2.size();++i){
            if(version2[i]=='.'){
                vecArr2.push_back(cur);
                cur=0;
            }
            else{
                int t=version2[i]-'0';
                cur=cur*10+t;
            }
        }
        if(cur!=0){
            vecArr2.push_back(cur);
        }
        int idx1=0,idx2=0;
        while(idx1<vecArr1.size()||idx2<vecArr2.size()){
            if(idx1<vecArr1.size() && idx2<vecArr2.size()){
                if(vecArr1[idx1]<vecArr2[idx2]){
                    return -1;
                }
                else if(vecArr1[idx1]>vecArr2[idx2]){
                    return 1;
                }
                ++idx1,++idx2;
            }
            else if(idx1<vecArr1.size()){
                if(vecArr1[idx1]!=0){
                    return 1;
                } 
                ++idx1;
            }
            else{
                if(vecArr2[idx2]!=0){
                    return -1;
                } 
                ++idx2;                
            }
        }
        return 0;
    }
};
